package io.renren.modules.sys.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.sys.entity.MaterialpropertyEntity;
import io.renren.modules.sys.service.MaterialpropertyService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;



/**
 * 产品扩展字段表
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-11-22 14:29:36
 */
@RestController
@RequestMapping("sys/materialproperty")
public class MaterialpropertyController {
    @Autowired
    private MaterialpropertyService materialpropertyService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:materialproperty:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = materialpropertyService.queryPage(params);

        return R.ok().put("page", page);
    }

    @RequestMapping("/findBy")
    public R findBy(@RequestParam Map<String, Object> params){
        Object nativeName = params.get("nativeName");
        List<MaterialpropertyEntity> nativeName1 = materialpropertyService.selectList(new EntityWrapper<MaterialpropertyEntity>().like("NativeName", nativeName == null ? "" : nativeName.toString()).orderBy("sort"));
        return R.ok().put("rows", nativeName1).put("total",nativeName1.size());
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:materialproperty:info")
    public R info(@PathVariable("id") Long id){
        MaterialpropertyEntity materialproperty = materialpropertyService.selectById(id);

        return R.ok().put("materialproperty", materialproperty);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:materialproperty:save")
    public R save(@RequestBody MaterialpropertyEntity materialproperty){
        materialpropertyService.insert(materialproperty);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:materialproperty:update")
    public R update(@RequestBody MaterialpropertyEntity materialproperty){
        ValidatorUtils.validateEntity(materialproperty);
        materialpropertyService.updateAllColumnById(materialproperty);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:materialproperty:delete")
    public R delete(@RequestBody Long[] ids){
        materialpropertyService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
